package rollercoaster.train;

import rollercoaster.commons.Vertex2D;
import rollercoaster.commons.interfaces.Surface3D;
import rollercoaster.commons.interfaces.TextureCoordinateEvaluator;

public class BorderTextureCoordinateEvaluator implements TextureCoordinateEvaluator{

	public Vertex2D evaluateTextureCoordinates(Surface3D surface, float u, float v) {
		float dividendU=2*(surface.getEndUPoint()-surface.getStartUPoint()-1);
		float dividendV=2*(surface.getEndVPoint()-surface.getStartVPoint()-1);
		float multiplierU=2f;
		float multiplierV=2f;
		float suttraendU=0.5f;
		float suttraendV=0.5f;
		if(u<=surface.getStartUPoint()+1){
			multiplierU=1f;
			suttraendU=0f;
		}
		if(u>=surface.getEndUPoint()-1){
			multiplierU=1f;
			suttraendU=-(surface.getEndUPoint()-surface.getStartUPoint()-2);
		}
		if(v<=surface.getStartVPoint()+1){
			multiplierV=1f;
			suttraendV=0f;
		}
		if(v>=surface.getEndVPoint()-1){
			multiplierV=1f;
			suttraendV=-(surface.getEndVPoint()-surface.getStartVPoint()-2);
		}
		
		return new Vertex2D((u-suttraendU)*multiplierU/dividendU, (v-suttraendV)*multiplierV/dividendV);
	}

}
